﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Gencode.PrsWeb.App;

namespace Gencode.PrsWeb.Modules
{
    public partial class DienstView : System.Web.UI.UserControl
    {
		DataView m_diensteDV = null;
		DataView m_planDV = null;

		public DienstView()
		{
			InitializeComponen();
		}

		private void InitializeComponen()
		{
			
		}

		private void InitializeData()
		{
			_comboDienstOrColor.Items.Add("Dienste");
			_comboDienstOrColor.Items.Add("Farben");
		}

        protected void Page_Load(object sender, EventArgs e)
        {
			if (!IsPostBack)
				InitializeData();

			User info = Session["USERRIGHTS"] as User;

            m_planDV = Gencode.PrsCommon.Data.Plan.PlanData.GetActivePlannames(info.Mandid, true);
            //ComboDataGenerator.FillComboPlan(info.Mandid, true);
			if (!IsPostBack)
			{
                
				//m_diensteDV = Gencode.PrsWeb.App.ListDataGenerator.FillListDienste(ref _listDienste, info.Mandid, true);
                m_diensteDV = PrsCommon.App.AppData.DataGenerator.GetDienste(info.Mandid, true);
                _listDienste.DataSource = m_diensteDV;
                _listDienste.DataValueField = "Anzeigename";
                _listDienste.DataBind();

				ComboDataGenerator.BindData(m_planDV, ref _comboPlan, "Name");

				if (Session["CBPLAN"] != null && Session["CBPLAN"].ToString() != string.Empty)
				{
					_comboPlan.SelectedIndex = int.Parse(Session["CBPLAN"].ToString());

                    //if (Session["CBDIENSTCOLOR"] != null && Session["CBDIENSTCOLOR"].ToString() != string.Empty)
                    //    _comboDienstOrColor.SelectedIndex = int.Parse(Session["CBDIENSTCOLOR"].ToString());

					if (Session["CBDIENSTINDEX"] != null && Session["CBDIENSTINDEX"].ToString() != string.Empty)
						_listDienste.SelectedIndex = int.Parse(Session["CBDIENSTINDEX"].ToString());
				}
				else
				{
					_comboDienstOrColor.Visible = false;// Attributes.Add("visibility", "hidden");
					_listDienste.Visible = false;// Attributes.Add("visibility", "hidden");
				}
			}
        }

		protected void comboPlan_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (_comboPlan.SelectedIndex > 0)
			{
                //Session["CBDIENSTCOLOR"] = _comboDienstOrColor.SelectedIndex;
				Session["CBPLAN"] = _comboPlan.SelectedIndex;
				Session["CBDIENSTINDEX"] = _listDienste.SelectedIndex;

				string planID = m_planDV[_comboPlan.SelectedIndex].Row[1].ToString();
				Response.Redirect("Personalplaner.aspx?PLID=" + planID);
			}
			else
			{
				Session["CBPLAN"] = null;
				Response.Redirect("Personalplaner.aspx");
			}
		}

		protected void listDienste_SelectedIndexChanged(object sender, EventArgs e)
		{
			User info = Session["USERRIGHTS"] as User;
			m_diensteDV = Gencode.PrsWeb.App.ListDataGenerator.FillListDienste(info.Mandid, true);
			if (m_diensteDV != null && m_diensteDV.Count > 0)
			{
				Session["DIENSTNAME"] = m_diensteDV[_listDienste.SelectedIndex].Row[2].ToString();
				Session["DIENSTID"] = m_diensteDV[_listDienste.SelectedIndex].Row[1].ToString();
			}

		}
    }
}